package cn.wolfcode.crm.Service.impl;

import cn.wolfcode.crm.Service.ICustomerTraceHistoryService;
import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.mapper.CustomerTraceHistoryMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {
    @Autowired
    private CustomerTraceHistoryMapper customerTraceHistoryMapper;
    @Override
    public void insert(CustomerTraceHistory record) {
        //封装客户的录入人和录入时间
        record.setInputUser(UserContext.getEmployee());
        record.setInputTime(new Date());
        customerTraceHistoryMapper.insert(record);
    }

    @Override
    public void updateByPrimaryKey(CustomerTraceHistory record) {
        customerTraceHistoryMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<CustomerTraceHistory> queryForList(QueryObject qo) {
        //查询结果集并分页
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),"input_time DESC");
        List<CustomerTraceHistory> list = customerTraceHistoryMapper.queryForList(qo);
        return new PageInfo<>(list);
    }
}
